package com.hxzy.config;

import com.hxzy.common.RabbitMQConst;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FanoutExchangeConfig {

    /**
     * 邮件队列
     * @return
     */
    @Bean
    public Queue mailQueue(){
        Queue  queue=new Queue(RabbitMQConst.MAIL_QUEUE);
        return queue;
    }

    /**
     * 短信队列
     * @return
     */
    @Bean
    public Queue smsQueue(){
        Queue  queue=new Queue(RabbitMQConst.SMS_QUEUE);
        return queue;
    }


    /**
     * 发布订阅模型交换机
     * @return
     */
    @Bean
    public FanoutExchange shopFanoutExchange(){
        FanoutExchange fanoutExchange=new FanoutExchange(RabbitMQConst.FANOUT_EXCHANGE);
        return fanoutExchange;
    }


    /**
     * sms_queue绑定给 发布订阅模型交换机 shopFanoutExchange
     * @return
     */
    @Bean
    public Binding smsQueueBindShopFanoutExchange(FanoutExchange shopFanoutExchange,Queue smsQueue){
        return BindingBuilder.bind(smsQueue).to(shopFanoutExchange);
    }


    /**
     * mail_queue绑定给 发布订阅模型交换机 shopFanoutExchange
     * @return
     */
    @Bean
    public Binding mailQueueBindShopFanoutExchange(FanoutExchange shopFanoutExchange,Queue mailQueue){
        return BindingBuilder.bind(mailQueue).to(shopFanoutExchange);
    }
}
